import mongoose from 'mongoose'
import { generateRawSchema } from 'zod-to-mongoose'
import { dictEntrySchema, dictActionValid } from '@packages/shared'
import { registerResource } from './core'

// 使用 zod-to-mongoose 生成 mongoose schema
const dictSchema = new mongoose.Schema(generateRawSchema({ schema: dictEntrySchema }), { timestamps: true })

const Dict = mongoose.model('Dict', dictSchema)

registerResource({
    model: Dict,
    description: '字典管理',
    action: ['CREATE', 'UPDATE', 'DELETE', 'LIST', 'ONE'],
    validator: dictActionValid,
})

export default Dict